package org.example;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;

public class HorseRace {

    //    10个线程模拟赛马，所有马到达终点裁判宣布成绩
    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {

        }
    }

    private static List<String> result = Collections.synchronizedList(new ArrayList<>());

    private static CountDownLatch countDownLatch = new CountDownLatch(1);

    private static CyclicBarrier cyclicBarrier = new CyclicBarrier(10);

    static class Horse implements Runnable {

        String name;

        @Override
        public void run() {
            try {
                countDownLatch.await();
                Thread.sleep((long) (Math.random() * 1000));
                System.out.println(name + "到达终点");
                cyclicBarrier.await();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }

}
